//
//  CommunityCell.m
//  CarLife
//
//  Created by yu on 2019/3/28.
//  Copyright © 2019年 jpas. All rights reserved.
//

#import "CommunityCell.h"
#import "PhotosContainerView.h"
#import "CommunityModel.h"

@implementation CommunityCell

- (void)awakeFromNib {
    [super awakeFromNib];
    
    UIView *lineView = [[UIView alloc] init];
    lineView.backgroundColor = kLineGrayColor;
    [self.contentView addSubview:lineView];
    
    lineView.sd_layout
    .leftSpaceToView(self.contentView, 0)
    .bottomSpaceToView(self.contentView, 0)
    .rightSpaceToView(self.contentView, 0)
    .heightIs(0.5);
    
    self.iconImgView.sd_layout
    .leftSpaceToView(self.contentView, 16)
    .topSpaceToView(self.contentView, 16)
    .widthIs(kAutoWidth(36))
    .heightEqualToWidth();
    
    self.nicknameLabel.sd_layout
    .leftSpaceToView(self.iconImgView, 11)
    .topEqualToView(self.iconImgView)
    .heightIs(20);
    [_nicknameLabel setSingleLineAutoResizeWithMaxWidth:200];
    
    self.timeLabel.sd_layout
    .leftEqualToView(self.nicknameLabel)
    .bottomEqualToView(self.iconImgView)
    .heightIs(17);
    [_timeLabel setSingleLineAutoResizeWithMaxWidth:200];
    
    self.contentLabel.sd_layout
    .leftEqualToView(self.nicknameLabel)
    .topSpaceToView(self.iconImgView, 10)
    .rightSpaceToView(self.contentView, 16)
    .autoHeightRatio(0);
    self.contentLabel.sd_layout.maxHeightIs(_contentLabel.font.lineHeight * 4);
    
    self.photosContainer.sd_layout
    .leftEqualToView(self.nicknameLabel)
    .rightEqualToView(self.contentLabel)
    .topSpaceToView(self.contentLabel, 10);
    
    self.browseLabel.sd_layout
    .leftEqualToView(self.nicknameLabel)
    .topSpaceToView(self.photosContainer, 10)
    .heightIs(17);
    
//    self.likeBtn.backgroundColor = [UIColor orangeColor];
    self.likeBtn.sd_layout
    .rightSpaceToView(self.contentView, 10)
    .centerYEqualToView(self.browseLabel)
    .heightIs(kAutoHeight(30))
    .widthIs(kAutoWidth(50));
    
    self.lineView.sd_layout
    .rightSpaceToView(self.likeBtn, 8)
    .centerYEqualToView(self.likeBtn)
    .heightIs(kAutoHeight(10))
    .widthIs(0.5);
    
//    self.commentBtn.backgroundColor = [UIColor orangeColor];
    self.commentBtn.sd_layout
    .rightSpaceToView(self.lineView, 8)
    .centerYEqualToView(self.lineView)
    .heightRatioToView(self.likeBtn, 1)
    .widthRatioToView(self.likeBtn, 1);
    
    
}

- (void)setCModel:(CommunityModel *)cModel
{
    _cModel = cModel;
    
    if (cModel.picNamesArray.count > 0) {
        _photosContainer.hidden = NO;
        _photosContainer.photoNamesArray = cModel.picNamesArray;
        _browseLabel.sd_layout.topSpaceToView(_photosContainer, 10);
    } else {
        _photosContainer.hidden = YES;
        _browseLabel.sd_layout.topSpaceToView(_contentLabel, 10);
    }
    
    _iconImgView.image = [UIImage imageNamed:cModel.iconUrl];
    _nicknameLabel.text = cModel.nickname;
    _timeLabel.text = cModel.time;
    _contentLabel.text = cModel.content;
    _browseLabel.text = cModel.browseCount;
    
    NSString *commentCount;
    if (!cModel.commentCount.length) {
        commentCount = @"评论";
    } else {
        commentCount = cModel.commentCount;
    }
    
    NSString *likeCount;
    if (!cModel.likeCount.length) {
        likeCount = @"赞";
    } else {
        likeCount = cModel.likeCount;
    }
    
    [_commentBtn setTitle:commentCount forState:UIControlStateNormal];
    [_likeBtn setTitle:likeCount forState:UIControlStateNormal];
    
    [self setupAutoHeightWithBottomView:self.browseLabel bottomMargin:10];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
